home *** CD-ROM | disk | FTP | other *** search
/ IRIX 6.4 Applications 1997 August / SGI IRIX 6.4 Applications 1997 August.iso / dist / gateway.idb / usr / WebFace / Tasks / connect-ether-fddi.cgi.z / connect-ether-fddi.cgi
Encoding:
Text File  |  1997-07-30  |  8.0 KB  |  281 lines

  1. #!/usr/bin/perl5
  2. #
  3. # connect-ether-fddi.cgi
  4. #
  5. # Copyright 1988-1996 Silicon Graphics, Inc.
  6. # All rights reserved.
  7. #
  8. # This is UNPUBLISHED PROPRIETARY SOURCE CODE of Silicon Graphics, Inc.;
  9. # the contents of this file may not be disclosed to third parties, copied or
  10. # duplicated in any form, in whole or in part, without the prior written
  11. # permission of Silicon Graphics, Inc.
  12. #
  13. # RESTRICTED RIGHTS LEGEND:
  14. # Use, duplication or disclosure by the Government is subject to restrictions
  15. # as set forth in subdivision (c)(1)(ii) of the Rights in Technical Data
  16. # and Computer Software clause at DFARS 252.227-7013, and/or in similar or
  17. # successor clauses in the FAR, DOD or NASA FAR Supplement. Unpublished -
  18. # rights reserved under the Copyright Laws of the United States.
  19. #
  20. # $Id: connect-ether-fddi.cgi,v 1.43 1997/04/17 23:43:37 shotes Exp $
  21.  
  22. require "/usr/OnRamp/lib/OnRamp.pm";
  23. require "/usr/OnRamp/lib/java.pm";
  24.  
  25. if (!$ARGV[0]) { printf("Location: %s%c%c","/tasks/Tasks.connect-start.cgi",10,10); } 
  26.  
  27. $myname = "connect-ether-fddi.cgi";
  28. $temp = "task.tmp";
  29. $action= "connect-ether-fddi.cgi?loop";
  30.  
  31. $it = "<td align=right><font size=4>";
  32. $ni = "</font></td>";
  33. $bo = "<td><font size=5><i>";
  34. $nb = "</i></font></td>";
  35.  
  36. @find_vals = ('interface','address','netmask');
  37.  
  38. &get_fields;
  39.  
  40. &getList;
  41.  
  42. if ($ARGV[0] eq 'loop') { %vals = %fld; }
  43. else { &readValues; }
  44.  
  45. if ($ARGV[0] eq loop) {
  46.     &errorCheck;
  47.     &writeFile;
  48.  
  49.     $go = "/tasks/connect-end.cgi?e";
  50.     #printf("Location: %s%c%c",$go,10,10); 
  51.     print "Content-type: text/html\n\n";
  52.     print "<HTML><HEAD>";
  53.     print "<META HTTP-EQUIV=\"refresh\" CONTENT=\"0; URL=$go\">";
  54.     print "</HEAD><BODY></BODY></HTML>";
  55.     exit 0;
  56. }
  57.  
  58.  
  59. &generic;
  60.  
  61. sub get_iflabel {
  62.     $_ = $_[0];
  63.     if( (/^et/) || (/^ec/) || (/^ee/) || (/^enp/) ) {
  64.         $lb = "Ethernet $_";
  65.     }
  66.     elsif (/^egl/) {
  67.         $lb = "EFast Eagle $_";
  68.     }
  69.     elsif (/^fxp/) {
  70.         $lb = "EFast FXP $_";
  71.     }
  72.     elsif (/^ep/) {
  73.         $lb = "EPlex Ether $_";
  74.     }
  75.     elsif (/^ipg/) {
  76.         $lb = "FDDIXPress $_";
  77.     }
  78.     elsif (/^xpi/) {
  79.         $lb = "FDDI $_";
  80.     }
  81.     elsif ( (/^fv/) || (/^mtr/) || (/^gtr/) ) {
  82.         $lb = "TokenRing $_";
  83.     }
  84.     elsif (/^ef/) {
  85.      $lb = "100BaseTx Ether $_";
  86.     }
  87.     elsif (/^atm/) {
  88.      $lb = "ATM $_";
  89.     }
  90.     elsif (/^hippi/) {
  91.      $lb = "HIPPI $_";
  92.     }
  93.     else {
  94.         $lb = $_;
  95.     }
  96.     $lb;
  97. }
  98.  
  99. sub readValues {
  100.     open(IN,"< $temp");
  101.     while(<IN>) {
  102.         @items = split(/=/);
  103.         foreach $arg (@find_vals) {
  104.             if ($arg eq $items[0]) { 
  105.                 if ($items[1] ne "\n") {
  106.                     $vals{$arg} = $items[1];
  107.                     chop $vals{$arg};
  108.                 }
  109.             }
  110.         }
  111.     }
  112.     close(IN);
  113. }
  114.  
  115. sub errorCheck {
  116.     &error("Network interface IP address required.") if !$fld{'address'};
  117.     &error("Invalid IP address.") if &check_ipaddr($fld{'address'});
  118.     &error("Netmask required.") if !$fld{'netmask'};
  119.     &error("Invalid netmask.") if &check_netmask($fld{'netmask'});
  120. }
  121.  
  122. sub error {
  123.     $error = $_[0];
  124.     %vals = %fld;
  125.     @items = split(/\s+/,$vals{'interface'});
  126.     $vals{'interface'} = $items[1];
  127.     &generic;
  128.     exit 0;
  129. }
  130.     
  131. sub writeFile {
  132.     undef %terms;
  133.     open(IN,"< $temp");
  134.     while(<IN>) {
  135.         @items = split(/=/);
  136.         chop $items[1];
  137.         $terms{$items[0]} = $items[1];
  138.     }
  139.     close(IN);
  140.     foreach $arg (@find_vals) {
  141.         $terms{$arg} = $fld{$arg};
  142.     }
  143.     open(OUT,"> $temp");
  144.     foreach $arg (keys(%terms)) {
  145.         print OUT "$arg=$terms{$arg}\n";
  146.     }
  147.     close(OUT);
  148. }
  149.  
  150. sub getList {
  151.     undef @IFlist;
  152.     undef @IPlist;
  153.     open(IN,"/usr/OnRamp/bin/htnetwork | ");
  154.     $needMask = 1;
  155.     while(<IN>) {
  156.         @items = split(/:/);
  157.         if ($items[0] ne '0') {
  158.             if ($needMask) { 
  159.                 $vals{'netmask'} = $items[4];
  160.                 $vals{'address'} = $items[3]; 
  161.                 $needMask = 0; 
  162.             } 
  163.             push(@IFlist,$items[1]); 
  164.             push(@IPlist,$items[2]); 
  165.         }
  166.     }
  167.     close(IN);
  168. }
  169.  
  170. sub generic {
  171.     print "Content-type: text/html\n\n";
  172.     print "<html><head><title>Ethernet-FDDI Configuration</title>\n";
  173.     print "<script language=\"JavaScript\">\n<!--\n";
  174.  
  175.     # JavaScript
  176. print "
  177. $js_error_box
  178. $js_ip
  179. function Next()  {
  180.     form = document.ether;
  181.     if (form.address.value == \"\") {
  182.         errorBox (form.address, \"The network interface IP address is required.\");
  183.         return;
  184.     } 
  185.     if (!testIPaddress(form.address.value, 0)) {
  186.         errorBox (form.address, \"The network interface address is invalid.\");
  187.         return;
  188.     }
  189.     if (form.netmask.value == \"\") {
  190.         errorBox (form.netmask, \"The netmask is required.\");
  191.         return;
  192.     }
  193.     if (!testIPaddress(form.netmask.value, 1)) {
  194.         errorBox (form.netmask, \"The netmask is invalid.\");
  195.         return;
  196.     }
  197.     setTimeout('form.submit()',0);
  198.     return;
  199. }\n";
  200.  
  201. print "//-->\n";
  202. print "</script></head>\n\n";
  203.  
  204.     print "<body bgcolor=\'c7ded4\' background=/tasks/connect-task.bg.gif>\n";
  205.  
  206.     if ($error) {
  207.         print "<font size=4 color=ff0000><b>Error: </b>$error<br></font>";
  208.     }
  209.     print "<i>$message</i>";
  210.  
  211.     print "<table width=100%>",
  212.           "<tr><th align=left><h1>Ethernet-FDDI Configuration</h1></th>\n",
  213.           "<th align=right><a href=\"/newsplash.shtml\">",
  214.           "<img height=55 width=57 border=0 src=/tasks/home.gif></a>\n",
  215.           "  <a href=\"/tasks/Tasks.shtml\">",
  216.           "<img height=55 width=57 border=0 src=/tasks/back.gif></a>",
  217.           "</tr></table>\n\n";
  218.  
  219.     printf("<form name=\"ether\" action=\"%s\" method=post>\n", $action);
  220.     
  221.     print "<center><table width=620>";
  222.  
  223.     undef @locList;
  224.     for($i=0;$i<=$#IFlist;$i++) {
  225.         $label = &get_iflabel($IFlist[$i]);
  226.         push(@locList,"$label");
  227.     }
  228.  
  229.     print "<tr>$bo Device name for the network interface: $nb \n$it", 
  230.           &select_list("interface",$vals{'interface'},*locList),
  231.           "$ni </tr>\n";
  232.     print "    <tr><td colspan=2>
  233.     The IRIX operating system assigns a device name to each network 
  234.     interface that it detects on the Internet Gateway when the system 
  235.     is powered on. Select the device name of the interface that you plan 
  236.     to use for the connection to your Internet service provider.
  237.     </td></tr><tr><td> </td></tr>\n\n";
  238.  
  239.     print "<tr>$bo IP address of the network interface: $nb \n$it", 
  240.         &text("address",$vals{'address'},15),
  241.         "$ni </tr>\n";
  242.     print "    <tr><td colspan=2>
  243.     Each network interface must be assigned an IP address that identifies 
  244.     it to the network. An Internet address has four parts: each part, 
  245.     or octet, is separated by a dot and contains a decimal value in the 
  246.     range of 0 to 255. A portion of the address (usually the first two or 
  247.     three octets) designates a network, and the remaining octet designates 
  248.     a host on the network.  Your ISP should have assigned you an address 
  249.     to use for this interface, or a range of addresses from which you must 
  250.     assign one.
  251.     </td></tr><tr><td> </td></tr>\n\n";
  252.  
  253.     print "<tr>$bo Netmask for your network: $nb \n$it",
  254.         &text("netmask",$vals{'netmask'},15), 
  255.         "$ni </tr>\n";
  256.     print "    <tr><td colspan=2>
  257.     A network mask is applied to an Internet address to designate the 
  258.     portion of the address that identifies the host. Enter your network 
  259.     mask in dot notation (four dot-separated numbers) or as a hexadecimal 
  260.     number.  Your ISP should have specified the network mask for this 
  261.     network.
  262.     </td></tr>\n";
  263.     print "</table></center>\n";
  264.  
  265.     print '<MAP NAME="js_map1">',
  266.     '    <AREA SHAPE="rect" COORDS="0,0,59,52" HREF="javascript:Previous()"
  267.     onMouseOver="window.status=\'\';return true">',
  268.     '</MAP>';
  269.     print "\n";
  270.     print '<MAP NAME="js_map2">',
  271.     '    <AREA SHAPE="rect" COORDS="0,0,59,52" HREF="javascript:Next()"
  272.     onMouseOver="window.status=\'\';return true">',
  273.     '</MAP>';
  274.     print "\n";
  275.     print '<IMG SRC="/tasks/rightarrow.gif" BORDER=0 USEMAP="#js_map2" align="right">';
  276.     print "\n";
  277.     print '<IMG SRC="/tasks/leftarrow.gif" BORDER=0 USEMAP="#js_map1" align="right">';
  278.  
  279.     print "\n</form></body></html>";
  280. }
  281.